package com.yiqi.liebang.feature.mine.view;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.liebang.R;
import com.yiqi.liebang.entity.bo.CommentBo;
import com.yiqi.liebang.framework.api.UserApi;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class CommentFriendActivity extends BaseActivity {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.btv_user_comment_name)
    TextView mBtvUserCommentName;
    @BindView(R.id.edt_user_comment_content)
    EditText mEdtUserCommentContent;
    @BindView(R.id.btn_user_comment)
    TextView mBtnUserComment;
    private String mUserUid;
    private String mUserName;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_comment_friend;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        mUserUid = this.getIntent().getStringExtra("userUid");
        mUserName = this.getIntent().getStringExtra("userName");
        initToolBar(mToolbar, "给" + mUserName + "点评", true, true);
        mBtvUserCommentName.setText(Html.fromHtml("综合评价<font color=\"#2AA0F8\">" + mUserName + "</font>（建议结合具体事例点评）"));
    }


    @Override
    protected void initData() {

    }


    @OnClick(R.id.btn_user_comment)
    public void onViewClicked() {
        if (TextUtils.isEmpty(mEdtUserCommentContent.getText().toString())) {
            showMsg("请输入点评内容！");
            return;
        }
        if (mEdtUserCommentContent.getText().toString().length() < 24) {
            showMsg("点评内容不能少于24个汉字！");
            return;
        }
        AM.api().createApiService(UserApi.class)
                .userComment(new CommentBo(mUserUid, mEdtUserCommentContent.getText().toString()))
                .compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        showMsg("点评成功！");
                        finish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        showMsg(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
